# -*- coding: utf-8 -*-
from src.com.ydzy.util.base_util import BaserUtil
from src.com.ydzy.util.file_util import FileClient
from src.com.ydzy.util.sql_util import MySQLUtils


# INSERT INTO `audit_local`.`audit_dict` (`id`, `pid`, `type`, `code`, `content`, `describe`, `ext1`, `ext2`, `canEdit`, `status`, `createTime`, `createUser`, `updateTime`, `updateUser`, `seq`) VALUES (1231, NULL, 'z_operate_type', 'z_operate_type', '操作类型', '', '', '', '1', '1', '2024-05-31 10:01:58', NULL, NULL, NULL, NULL);

db = MySQLUtils('192.168.8.234', 3306, 'root', 'root', 'audit_local')
base_client=BaserUtil()
file_client=FileClient()


dict=\
{
"0001":"登录",
"0002":"登出",
"1001":"使用资源类查询",
"2001":"bk类",
"4001":"导入导出类",
"5000":"普通查询",
"6000":"修改",
"7000":"删除",
"8000":"新增",
"9101":"风险传递",
"9102":"指令下发",
"9103":"环境变更",
"9104":"用户注册",
"9105":"用户认证",
"9106":"授权",
"9107":"鉴权",
"9111":"令牌处理",
"9201":"应用服务",
"9999":"其它",
}



table_name='audit_dict'
condition="type='z_operate_type'"
root_data=db.retrieve_json(table=table_name,condition=condition)[0]
print(root_data)

sqls=[]
for k,v in dict.items():
    for k1, v1 in dict.items():
        copy=base_client.deep_copy(root_data)
        copy['id']=0
        copy['code']=k+'_'+k1
        copy['content']=v+'_'+v1
        copy['updateTime']=copy['createTime']
        sql=db.create(table=table_name,data=copy,camel_to_snake=False,exeute=False)
        sqls.append(sql)

write_sql="\n".join(sqls)
print(write_sql)
file_client.write(".\opearete.sql",write_sql)



# db.create('crawer_data', data[0])
